<%@ page import="database.CourseDb" %>
<%@ page import="database.User" %>
<%@ page import="java.util.List" %>
<%@ page import="utils.StringUtils" %>
<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: jimmyhsu
  Date: 2016/12/16
  Time: 13:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../../static/style/weui.css"/>
    <link rel="stylesheet" href="../../static/example/example.css"/>
    <link rel="stylesheet" href="../../static/style/myStyle.css"/>
    <link rel="stylesheet" href="../../static/css/bootstrap.css"/>
    <%
        String courseIdStr = request.getParameter("courseId");
        boolean enabled = true;
        if (StringUtils.isEmpty(courseIdStr)) {
            enabled = false;
        }
        int courseId = -1;
        List<User> usersInCourse = new ArrayList<User>();
        if (enabled) {
            courseId = Integer.parseInt(request.getParameter("courseId"));
            usersInCourse = CourseDb.selectStudentsInCourse(courseId);
        }
    %>
</head>
<body style="background-color: transparent; color: #ffffff;">
<%@include file="Do/checkAdminLogin.jsp"%>
<table class="table table-bordered">
    <caption><%=enabled?CourseDb.selectCourseById(courseId).getName():"未选择课程"%><br></caption>
    <thead>
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>操作</th>
    </tr>
    </thead>

    <%
        for (User user : usersInCourse) {
        %>
    <tr>
        <td><%=user.getId()%></td>
        <td><%=user.getName()%></td>
        <td>
            <button class="btn btn-danger" style = "position: relative" type = "button"  onclick="removeStudent('<%=user.getId()%>', '<%=courseId%>')">移除</button>
        </td>
    </tr>
    <% }%>

</table>

</body>
<script src="../../static/js/jquery-1.10.2.js"></script>
<script src="../../static/js/bootstrap.js"></script>
<script>
    function removeStudent(studentId, courseId)
    {
        if (window.confirm("将要在此课程中移除这名学生。确定吗?")) {
            location.href = 'Do/doRemoveStudentFromCourse.jsp?studentId=' + studentId + '&courseId=' + courseId;
        }
    }
</script>
</html>
